<script src="http://localhost/php/login/js/jquery.js">
</script>
<script>
$(document).ready(function(){
  $(".firstname").keyup(function(){
   var firstname = $(".firstname").val();
    $.ajax({url:"autocomplete.php?value=" +firstname,
	
	
	success:function(result){
	//alert('sss');
	  $(".option").show();
      $(".option").html(result);
		  $(".option").each(function(){
			  $(".option ul li").click(function(){
				  var textvalue = $(this).html();
				  $(".firstname").val(textvalue);
				  $(".option").hide();
			  //alert($(this).attr('id'));
				  var roleid = $(this).attr('id');
				  $(".roleid").val(roleid);
			  });
		  });
    },
	
	
	error:function(result){
      $(".option").html(result);
    }
	
	
	
	});
  });
});
</script>

<?php
$connect = mysql_connect('localhost','root','');
mysql_select_db("admintool");
error_reporting(E_ALL ^ E_NOTICE);
session_start();
?>
<?php
if($_SESSION["loggedin"]==true && $_SESSION["role"]==admin)
{
if(isset($_SESSION[msg]))
{
echo $_SESSION[msg];
unset($_SESSION[msg]);
}
?>
<?php 


?>
<form action="add.php" method="post">
<label>Employee Name</label>
<input type="text" value="<?php echo $_POST['addempname'];?>" name="addempname" /><br><br>
<label>Father Name</label>
<input type="text" value="<?php echo $_POST['addfathername'];?>" name="addfathername" /><br><br>
<label>Mother Name</label>
<input type="text" value="<?php echo $_POST['addmothername'];?>" name="addmothername" /><br><br>
<label>Address</label>
<textarea value="<?php echo $_POST['addaddress'];?>" name="addaddress" ></textarea><br><br>
<label>PAN card No</label>
<input type="text" value="<?php echo $_POST['addpanno'];?>" name="addpanno" /><br><br>
<label>Email id</label>
<input type="text" value="<?php echo $_POST['addemailid'];?>" name="addemailid" /><br><br>
<label>Mobile/Telephone</label>
<input type="text" value="<?php echo $_POST['addmobile'];?>" name="addmobile" /><br><br>

<label>Login Username</label>
<input type="text" value="<?php echo $_POST['addusername'];?>" name="addusername" /><br><br>
<label>Login Password</label>
<input type="text" value="<?php echo $_POST['addpassword'];?>" name="addpassword" /><br><br>
<label>Role</label>
<input type="text" class="firstname"  name="addrole1" value="<?php echo $_POST['addrole'];?>"/>

<input type="text" class="roleid" name="addrole" style="display:none;" />

<div class="option" style="display:none;  border: 1px solid;
    height: 39px;
    left: 32px;
    margin-right: 103px;
    overflow-x: auto;
    overflow-y: scroll;
    position: relative;
    width: 143px;"></div>
<!--<select name="addrole">-->
<?php /*while($rolemg = mysql_fetch_array($roles))
{
?>
<option value="<?php echo $rolemg['roleid'];?>"><?php echo $rolemg['rolename']; ?></option>
<?php }*/?>
<!--</select>-->
<input type="submit" value="save" name="addform" />
</form>
<?php

if(isset($_POST['addform']))
{
print_r($_post);
$addempname = $_POST['addempname'];
$addfathername = $_POST['addfathername'];
$addmothername = $_POST['addmothername'];
$addaddress = $_POST['addaddress'];
$addpanno = $_POST['addpanno'];
$addemailid = $_POST['addemailid'];
$addmobile = $_POST['addmobile'];
$addusername = $_POST['addusername'];
$addpassword = $_POST['addpassword'];
$addrole = $_POST['addrole'];


$insert = "INSERT into adminform(addempname,addfathername,addmothername,addaddress,addpanno,addemailid,addmobile,addusername,addpassword) 
values('$addempname','$addfathername','$addmothername','$addaddress','$addpanno','$addemailid','$addmobile','$addusername','$addpassword')";
//print_r($insert);
$insertresult = mysql_query($insert);

$insertrole = "INSERT into userrole(adminid,roleid) values(LAST_INSERT_ID(),'$addrole')";
$insertroleresult = mysql_query($insertrole);
header("Location: user_list.php");
}
}
else
{
header("Location: login.php");
}
?>